import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
let router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: '登录',
      component: () => import('@/views/login/index')
    },
    {
      path: '/404',
      component: (resolve) => require(['@/views/error/404'], resolve),
      hidden: true
    },
    {
      path: '/401',
      component: (resolve) => require(['@/views/error/401'], resolve),
      hidden: true
    },
    {
      path: '/home',
      name: '首页',
      component: () => import('@/views/home/index')
    },
    {
      path: '/setting',
      name: '设置',
      component: () => import('@/views/setting/index')
    },
    {
      path: '/editPassword',
      name: '修改密码',
      component: () => import('@/views/setting/editPassword/index')
    },
    {
      path: '/editInfo',
      name: '修改信息',
      component: () => import('@/views/setting/editInfo/index')
    },
    {
      path: '/userReg',
      name: '注册统计',
      component: () => import('@/views/userReg/index')
    },
    {
      path: '/earnings',
      name: '收益统计',
      component: () => import('@/views/earnings/index')
    },
    {
      path: '/userStatistics/:agentId',
      name: '代理商数据统计',
      component: () => import('@/views/agent/statistics/index')
    },
    {
      path: '/agentList',
      name: '我的代理商列表',
      component: () => import('@/views/agent/list'),
      // meta: {
      //   keepAlive: true
      // }
    },
    {
      path: '/promotion/:inviteCode',
      name: '聚缘公园',
      component: () => import('@/views/promotion/index'),
      meta: {
        title: '聚缘公园-快速靠谱的约会平台！'
      }
    },
    {
      path: '/agentAdd',
      name: '新增代理商',
      component: () => import('@/views/agent/add')
    },
    {
      path: "*", // 此处需特别注意置于最底部
      redirect: "/404"
    }
  ],
});


router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
})

export default router;
